//字符串 - 中心扩展算法
class Solution 
{
public:
    string longestPalindrome(string s) 
    {
        int len = 0, begin = 0;
        for(int i = 0; i < s.size(); i++)
        {
            //奇数扩展
            int left = i, right = i;
            while(left >= 0 && right < s.size() && s[left] == s[right]) left--, right++;
            if(right - left - 1 > len)
            {
                begin = left + 1;
                len = right - left - 1; 
            }

            //偶数扩展
            left = i, right = i + 1;
            while(left >= 0 && right < s.size() && s[left] == s[right]) left--, right++;
            if(right - left - 1 > len)
            {
                begin = left + 1;
                len = right - left - 1; 
            }
        }
        return s.substr(begin, len);
    }
};